function divide(form){
	if(!form || form.length < 1) return;
	var content=c='',all_role=document.getElementById('all_role').innerHTML;
	for(var i = form.length-1;i>0;i--){
		if(form[i].checked && form[i].name=='applyidarray[]'){
			c=form[i].parentNode.innerHTML;
			//c=c.substring(c.indexOf('>')+2);
			c= '<input checked="checked" ' + c.substring(Math.max(c.indexOf('input'), c.indexOf('INPUT')) + 6);
			c=c.replace('actl_','').replace('actl_','').replace('_menu','');
			//c=c.replace('<DIV style=\"DISPLAY: none\"','</td><td><DIV ');
			//c=c.replace('onmouseout=\"this.style.display=\'hidden\'\"','');
			content += '<tr><td>' + c + '</td><td><select name="role_' + form[i].value + '" class=" wd ">' + all_role + '</select></td></tr>';
		}
	}
	if(!content){
		showDialog('请选择要分工的用户！', 'alert');
	} else {
		c=document.getElementById('applylistform').outerHTML;
		c=c.substring(0, Math.max(c.indexOf('table'), c.indexOf('TABLE')) - 2);
		
		showDialog(c + '<div class="c" id="divide"><table summary="" class="actl" cellpadding="0" cellspacing="0"><tbody>' + content + '</tbody></table><div class="o pns"><button type="submit" class="pn pnc" value="true" name="applylistsubmit" onclick="this.form.operation.value=\'divide\';"><span>提交</span></button></div></td><td class="m_r"></div></form>', 'info', '活动分工');
	}
}
//打印报名表
function print_apply(tid, applyid, form){
	if(applyid == 'select'){
		applyid = '';
		if(form){
			for(var i = form.length-1;i>0;i--){
				applyid += (form[i].checked && form[i].name=='applyidarray[]') ? (form[i].value + ',') : '';
			}
			if(applyid && applyid.charAt(applyid.length-1) == ','){
				applyid = applyid.substring(0, applyid.length-1);
			}
		}
	}
	if(!applyid){
		showDialog('请选择要打印的用户！', 'alert');
		return;
	}
	window.open('plugin.php?id=donkey_activity:print&tid='+tid+'&applyid='+applyid);
}

//导出报名表
function export_apply(tid){
	window.open('plugin.php?id=donkey_activity:export&tid='+tid);
}

//取消报名
function act_cancel(){
	showDialog($('activityjoincancel').innerHTML, 'info', '取消报名');
}
//我要报名
function act_apply(){
	showDialog($('activityjoin').innerHTML, 'info', '报名');
}
//替人报名
function act_apply4other(){
	showDialog('<div class="c"><table summary="" class="actl" cellpadding="0" cellspacing="0"><tbody><tr><td id="td_realname"><div class="rq mtn alert_error" id="showerror_realname">对不起，替人报名功能正在开发中，稍后对外开放！</div></td></tr></tbody></table><div class="o pns"><button type="submit" class="pn pnc" onclick="hideMenu(\'fwin_dialog\', \'dialog\')"><span>关闭</span></button></div></td><td class="m_r"></div>', 'info', '提示');
}

//表单直接相互关联
function makeEvent(obj){
	if(!obj || !obj.id || !rules) return;
	var id=obj.id.replace('_defval', '');
	if(!id) return;
	var r, t;
	for(var i=0;i<rules.length;i++){
		r=rules[i];
		if(r[0]!=id)continue;
		if(r[1]=='eq'){
			if(r[4]=='hidden'){
				$('div_'+r[3]).style.display=(obj.value==r[2])?'none':'';
			} else if(r[4]=='setval' && obj.value==r[2]) {
				t=$(r[3]);
				if(!t)t=$(r[3]+'_defval');
				if(!t)t=$(r[3]+'message');
				if(t)t.value=r[5];
			}
		}
	}
}
//设置领队
function setLeader(obj, id){
	$(id).value=obj.value;
	$(id+'_disp').value=(obj.value=='')?'':obj.options[obj.selectedIndex].text.replace('(认证)','');
}
//用户输入后重新检查领队
function resetLeader(obj, id){
	obj.value=trim(obj.value);
	var sel=$(id+'_select');
	sel.value='';
	
	for(var i=0;i<sel.options.length;i++){
		if(obj.value==sel.options[i].text.replace('(认证)','')){
			sel.selectedIndex=i;
			$(id).value=sel.value=sel.options[i].value;
			break;
		}
	}
	if(sel.value==''){
		$(id).value=obj.value;
		sel.selectedIndex=0;
	}
}

//设置城市地区：省/市，市/区，县/街道，乡镇
function setcity(){
	var ds = getFormValue('districtsetting');
	$(ds).value = getFormValue('birthprovince') + ' ' + getFormValue('birthcity')  + ' ' + getFormValue('birthdist')  + ' ' + getFormValue('birthcommunity');
}
//取得表单的值
function getFormValue(id){
	var obj=$(id);
	if(!obj)return '';
	obj=obj.value;
	return obj?obj:'';
}
//改变活动属性的字段类型，用于后台添加属性的时候调用
function changeType(type, value){
	if(!type)return;
	var new_value = $('new_value_div');
	var new_defval = $('new_defval_div');
	new_defval.style.display="none";
	new_value.style.display='';
	new_value.innerHTML=new_value.innerHTML='';
	if (type=='number'||type=='text'||type=='password'){
		new_value.innerHTML='<input type="'+type+'" class="'+type+'" name="new_value" id="new_value">';
	} else if (type=='textarea'||type=='richtext') {
		new_value.innerHTML='<textarea rows="6" cols="50" class="tarea width250" id="new_value" name="new_value"></textarea>';
		// ondblclick="textareasize(this, 1)" onkeyup="textareasize(this, 0)"
	} else if (type=='select'||type=='selects') {
		new_value.innerHTML='每行一个选项，格式：1=小培<br/><textarea rows="6" id="new_value" name="new_value" cols="50" class="tarea width250">'+(value?value:'')+'</textarea><button type="button" value="OK" onclick="setList(\'new\')">OK</button>';
		// ondblclick="textareasize(this, 1)" onkeyup="textareasize(this, 0)"
	} else if (type=='date'){
		new_value.innerHTML='<input type="text" class="txt" id="new_value" name="new_value" value="" onclick="showcalendar(event, this)" />';
	} else if (type=='datetime'){
		new_value.innerHTML='<input type="text" class="txt" id="new_value" name="new_value" value="" onclick="showcalendar(event, this, 1)" style="width:150px" />';
	} else if (type=='radio') {
		new_value.innerHTML='<ul class="vtop rowform"><li><input class="radio" type="radio" name="new_defval" value="1" checked="checked">&nbsp;是</li><li><input class="radio" type="radio" name="new_defval" value="0">&nbsp;否</li></ul>';
	} 
}
//设置列表的值，用于修改 select 所有选项，和默认选择的值
function setList(id){
	var value = $(id+'_value').value;
	if(!value)return;
	$(id+'_value_div').style.display="none";
	var new_defval = $(id+'_defval_div');
	new_defval.innerHTML="waiting...";
	new_defval.style.display="";
	value=value.replace('\r\n','\n').split('\n');
	var tmp,k,v,content='<select class="width250" name="' + id + '_defval" id="' + id + '_defval">\n';
	for(var i=0;i<value.length;i++){
		tmp=value[i].split('=');
		if(tmp.length>1){
			k=tmp[0];
			v=tmp[1];
		} else {
			k=i;
			v=tmp[0];
		}
		content += '<option value="'+k+'">'+v+'</option>\n';
	}
	new_defval.innerHTML = content + '</select><button type="button" value="Modify" onclick="switchValue(\''+id+'\')">Modify</button>';;
	return false;
}
//切换 select 所有选项文本编辑框，和默认选择的值select框
function switchValue(id){
	$(id+'_defval_div').style.display="none";
	$(id+'_value_div').style.display="";
}
//发帖时表单验证
function validate_extra() {
	//保存城市设置
	setcity();
	var all_field=getFormValue('all_field');
	if(!all_field || all_field==','){
		return true;
	}
	var fields=all_field.split(',');
	for(var i=1;i<fields.length;i++){
		if(!checkField(fields[i])){
			return false;
		}
	}
	return true;
}
function checkField(id){
	var obj=$(id);
	if(!obj)obj=$(id +'_defval');
	if(!obj)obj=$(id +'message');
	if(obj && !(obj.value)){
		showDialog(obj.parentNode.parentNode.parentNode.getElementsByTagName('dt')[0].innerText + '不能为空', 'alert', '', function () {obj.focus()});
		return false;
	}
	return true;
}